package com.shumm.controller;

import com.shumm.common.Result;
import com.shumm.po.ShangHanTiaoBian;
import com.shumm.service.ShangHanTiaoBianService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping("/shtb")
public class ShangHanTiaoBianController {
    @Autowired
    private ShangHanTiaoBianService service;

    @GetMapping("/list")
    private Result list() throws IOException {
        return service.list();
    }

    @PostMapping("/add")
    private Result add(@RequestParam String num,
                     @RequestParam String content,
                     @RequestParam String comment){
        ShangHanTiaoBian shtb = new ShangHanTiaoBian();
        shtb.setNum(Integer.valueOf(num));
        shtb.setContent(content);
        shtb.setComment(comment);
        return service.add(shtb);
    }

    @DeleteMapping("/delete")
    private Result delete(@RequestParam Integer id) {
        return service.deleteById(id);
    }

    @PostMapping("/update")
    private Result update(@RequestParam Integer id,
                          @RequestParam Integer num,
                          @RequestParam String content,
                          @RequestParam String comment) {
        ShangHanTiaoBian shtb = new ShangHanTiaoBian();
        shtb.setId(id);
        shtb.setNum(num);
        shtb.setContent(content);
        shtb.setComment(comment);
        return service.update(shtb);
    }

    @GetMapping("/selectById")
    private Result selectById(@RequestParam Integer id) {
        return service.selectById(id);
    }

    @GetMapping("/selectByContentOrComment")
    private Result selectByContentOrComment(@RequestParam String content,
                                            @RequestParam String comment,
                                            @RequestParam String name,
                                            @RequestParam Integer size,
                                            @RequestParam Integer num){
        return  service.selectByContentOrComment(content, comment, name, size, num);
    }
}
